

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <stack>

#include "common/utils.hpp"

std::vector<int> preorder(NTreeNode* root) {
    std::vector<int> ret;
    std::stack<NTreeNode*> stack;

    if (root != nullptr) stack.push(root);

    while(!stack.empty()) {
        NTreeNode* node = stack.top();
        stack.pop();

        ret.push_back(node->val);
        int len = node->nodes.size();
        for (int i = len - 1; i >= 0; i--) {
            stack.push(node->nodes[i]);
        }
    }

    return ret;
}

extern NTreeNode* commonNRoot;

int main() {
    std::vector<int> res = preorder(commonNRoot);
    printVector(res);
}